function[Optx,Opty,ValueRange,IteNum,OptTime]=opt_goldensection(a0,b0,delta)
% 黄金分割优化算法，亦称0.618优化算法
% 0.618的由来：是为了减少计算量，通过解析计算得出的值
% 参数设置：delta--精度设置；[a,b]--初始搜索区间;区间更新为[A(i),B(i)]；
% 输出为：Optx--寻优结果(最终区间的均值)；Opty--优化函数的最优值；ValueRange--最优解所在区间；
%           IteNum--迭代次数;OptTime--代码执行时间
% 插值点分别用u和v表示；精度更新为dist(i)
% 该代码需要在phi函数（目标函数）变化时进行修改
tic;
A(1) = a0;
B(1) = b0;
u(1) = a0+0.382*(b0-a0);
v(1) = a0+0.618*(b0-a0);
phi1 = phi(u(1));
phi2 = phi(v(1));
dist(1) = delta+1;   %预置dist>delta
i = 1;
while dist(i)>delta
    if phi1>phi2
        if dist(i)<=delta
            break
        else
            A(i+1) = u(i);
            B(i+1) = B(i);
            u(i+1) = v(i);
            v(i+1) = A(i+1)+0.618*(B(i+1)-A(i+1));
            phi1 = phi2;
            phi2 = phi(v(i+1));
        end
    else
        if dist(i)<=delta
            break
        else
            A(i+1) = A(i);
            B(i+1) = v(i);
            v(i+1) = u(i);
            u(i+1) = A(i+1)+0.382*(B(i+1)-A(i+1));
            phi2 = phi1;
            phi1 = phi(u(i+1));
        end
    end 
  dist(i+1) = B(i+1)-A(i+1);
  i = i+1;  
end
IteNum = i-1;
Optx = (A(i)+B(i))/2;
Opty = phi(Optx);
ValueRange = [A(i) B(i)];
toc; 
OptTime = toc;
function[uu]=phi(x)
    %函数定义，根据我们的需求进行修改
    Te=65;
    l4=5.5/1000;
    n=60*60;% 对时间分割
    t=60*60;% 总时长
    h_1 = 116.3024;
    h_2 = 8.6635;
    uu = General_Simulation(Te,x/1000,l4,h_1,h_2,t,n);
    uu = uu(153,3300);
end  
end